package io.gitee.chearnee.fw.common.component.converter;

import cn.hutool.core.date.LocalDateTimeUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.time.LocalDate;

/**
 * * RequestParam PathVariable 的反序列化 * @see RequestParam * @see PathVariable
 *
 * @author cn
 * @version 1.0
 * @description
 * @date 2022/5/10 15:09
 */
public class StringToLocalDateConverter implements Converter<String, LocalDate> {

  public LocalDate convert(String source) {
    if (!StringUtils.hasText(source)) {
      return null;
    }
    return LocalDateTimeUtil.of(Long.parseLong(source)).toLocalDate();
  }
}
